import 'package:flutter/material.dart';
import 'dart:math';

class SwitchPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return SwitchPageState();
  }
}

class SwitchPageState extends State<SwitchPage> {
  Color _randomColor() {
    var red = Random.secure().nextInt(255);
    var greed = Random.secure().nextInt(255);
    var blue = Random.secure().nextInt(255);
    return Color.fromARGB(255, red, greed, blue);
  }

  @override
  void initState() {
    super.initState();
  }

  bool check = false;
  bool _lights = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Switch Example"),
      ),
      body: Column(
        children: <Widget>[
          Switch(
            value: this.check,
            onChanged: (bool val) {
              this.setState(() {
                this.check = !this.check;
              });
            },
          ),
          Divider(),
          Switch.adaptive(
            value: this.check,
            activeColor: Colors.red, // 激活时原点颜色
            onChanged: (bool val) {
              this.setState(() {
                this.check = !this.check;
              });
            },
          ),
          Divider(),
          Switch(
            value: this.check,
            activeTrackColor: Colors.green,
            inactiveThumbColor: Colors.black,
            inactiveThumbImage: NetworkImage(
                'https://flutter.io/images/homepage/header-illustration.png'),
            activeThumbImage: NetworkImage(
                "https://flutter.io/images/homepage/screenshot-2.png"),
            inactiveTrackColor: Colors.yellow,
            activeColor: Colors.blue, // 激活时原点颜色
            onChanged: (bool val) {
              this.setState(() {
                this.check = !this.check;
              });
            },
          ),
          Divider(),
          SwitchListTile(
            title: const Text('Lights'),
            value: _lights,
            onChanged: (bool value) {
              setState(() {
                _lights = value;
              });
            },
            secondary: const Icon(Icons.lightbulb_outline),
          ),
        ],
      ),
    );
  }
}
